{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Channel</th>\n",
       "      <th>Region</th>\n",
       "      <th>Fresh</th>\n",
       "      <th>Milk</th>\n",
       "      <th>Grocery</th>\n",
       "      <th>Frozen</th>\n",
       "      <th>Detergents_Paper</th>\n",
       "      <th>Delicassen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>12669</td>\n",
       "      <td>9656</td>\n",
       "      <td>7561</td>\n",
       "      <td>214</td>\n",
       "      <td>2674</td>\n",
       "      <td>1338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>7057</td>\n",
       "      <td>9810</td>\n",
       "      <td>9568</td>\n",
       "      <td>1762</td>\n",
       "      <td>3293</td>\n",
       "      <td>1776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>6353</td>\n",
       "      <td>8808</td>\n",
       "      <td>7684</td>\n",
       "      <td>2405</td>\n",
       "      <td>3516</td>\n",
       "      <td>7844</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>13265</td>\n",
       "      <td>1196</td>\n",
       "      <td>4221</td>\n",
       "      <td>6404</td>\n",
       "      <td>507</td>\n",
       "      <td>1788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>22615</td>\n",
       "      <td>5410</td>\n",
       "      <td>7198</td>\n",
       "      <td>3915</td>\n",
       "      <td>1777</td>\n",
       "      <td>5185</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Channel  Region  Fresh  Milk  Grocery  Frozen  Detergents_Paper  Delicassen\n",
       "0        2       3  12669  9656     7561     214              2674        1338\n",
       "1        2       3   7057  9810     9568    1762              3293        1776\n",
       "2        2       3   6353  8808     7684    2405              3516        7844\n",
       "3        1       3  13265  1196     4221    6404               507        1788\n",
       "4        2       3  22615  5410     7198    3915              1777        5185"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=pd.read_csv(\"Wholesale customers data.csv\")\n",
    "data.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查看数据缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 440 entries, 0 to 439\n",
      "Data columns (total 8 columns):\n",
      " #   Column            Non-Null Count  Dtype\n",
      "---  ------            --------------  -----\n",
      " 0   Channel           440 non-null    int64\n",
      " 1   Region            440 non-null    int64\n",
      " 2   Fresh             440 non-null    int64\n",
      " 3   Milk              440 non-null    int64\n",
      " 4   Grocery           440 non-null    int64\n",
      " 5   Frozen            440 non-null    int64\n",
      " 6   Detergents_Paper  440 non-null    int64\n",
      " 7   Delicassen        440 non-null    int64\n",
      "dtypes: int64(8)\n",
      "memory usage: 27.6 KB\n"
     ]
    }
   ],
   "source": [
    "\n",
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Channel</th>\n",
       "      <th>Region</th>\n",
       "      <th>Fresh</th>\n",
       "      <th>Milk</th>\n",
       "      <th>Grocery</th>\n",
       "      <th>Frozen</th>\n",
       "      <th>Detergents_Paper</th>\n",
       "      <th>Delicassen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "      <td>440.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.322727</td>\n",
       "      <td>2.543182</td>\n",
       "      <td>12000.297727</td>\n",
       "      <td>5796.265909</td>\n",
       "      <td>7951.277273</td>\n",
       "      <td>3071.931818</td>\n",
       "      <td>2881.493182</td>\n",
       "      <td>1524.870455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.468052</td>\n",
       "      <td>0.774272</td>\n",
       "      <td>12647.328865</td>\n",
       "      <td>7380.377175</td>\n",
       "      <td>9503.162829</td>\n",
       "      <td>4854.673333</td>\n",
       "      <td>4767.854448</td>\n",
       "      <td>2820.105937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>55.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3127.750000</td>\n",
       "      <td>1533.000000</td>\n",
       "      <td>2153.000000</td>\n",
       "      <td>742.250000</td>\n",
       "      <td>256.750000</td>\n",
       "      <td>408.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>8504.000000</td>\n",
       "      <td>3627.000000</td>\n",
       "      <td>4755.500000</td>\n",
       "      <td>1526.000000</td>\n",
       "      <td>816.500000</td>\n",
       "      <td>965.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>16933.750000</td>\n",
       "      <td>7190.250000</td>\n",
       "      <td>10655.750000</td>\n",
       "      <td>3554.250000</td>\n",
       "      <td>3922.000000</td>\n",
       "      <td>1820.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>112151.000000</td>\n",
       "      <td>73498.000000</td>\n",
       "      <td>92780.000000</td>\n",
       "      <td>60869.000000</td>\n",
       "      <td>40827.000000</td>\n",
       "      <td>47943.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Channel      Region          Fresh          Milk       Grocery  \\\n",
       "count  440.000000  440.000000     440.000000    440.000000    440.000000   \n",
       "mean     1.322727    2.543182   12000.297727   5796.265909   7951.277273   \n",
       "std      0.468052    0.774272   12647.328865   7380.377175   9503.162829   \n",
       "min      1.000000    1.000000       3.000000     55.000000      3.000000   \n",
       "25%      1.000000    2.000000    3127.750000   1533.000000   2153.000000   \n",
       "50%      1.000000    3.000000    8504.000000   3627.000000   4755.500000   \n",
       "75%      2.000000    3.000000   16933.750000   7190.250000  10655.750000   \n",
       "max      2.000000    3.000000  112151.000000  73498.000000  92780.000000   \n",
       "\n",
       "             Frozen  Detergents_Paper    Delicassen  \n",
       "count    440.000000        440.000000    440.000000  \n",
       "mean    3071.931818       2881.493182   1524.870455  \n",
       "std     4854.673333       4767.854448   2820.105937  \n",
       "min       25.000000          3.000000      3.000000  \n",
       "25%      742.250000        256.750000    408.250000  \n",
       "50%     1526.000000        816.500000    965.500000  \n",
       "75%     3554.250000       3922.000000   1820.250000  \n",
       "max    60869.000000      40827.000000  47943.000000  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Fresh列到Delicassen列的数据数量级大小差别很大，在聚类前需要进行标准化\n",
    "\n",
    "关于标准化、归一化、Normalizer的总结\n",
    "一、数据标准化 StandardScaler (基于特征矩阵的列，将属性值转换至服从正态分布) 标准化是依照特征矩阵的列处理数据，其通过求z-score的方法，将样本的特征值转换到同一量纲下 常用与基于正态分布的算法，比如回归\n",
    "\n",
    "二、数据归一化 MinMaxScaler （区间缩放，基于最大最小值，将数据转换到0,1区间上的） 提升模型收敛速度，提升模型精度 常见用于神经网络\n",
    "\n",
    "三、Normalizer （基于矩阵的行，将样本向量转换为单位向量） 其目的在于样本向量在点乘运算或其他核函数计算相似性时，拥有统一的标准 常见用于文本分类和聚类、logistic回归中也会使用，有效防止过拟合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.70833271, 0.53987376, 0.42274083, 0.01196489, 0.14950522,\n",
       "        0.07480852],\n",
       "       [0.44219826, 0.61470384, 0.59953989, 0.11040858, 0.20634248,\n",
       "        0.11128583],\n",
       "       [0.39655169, 0.5497918 , 0.47963217, 0.15011913, 0.2194673 ,\n",
       "        0.48961931],\n",
       "       ...,\n",
       "       [0.36446153, 0.38846468, 0.7585445 , 0.01096068, 0.37223685,\n",
       "        0.04682745],\n",
       "       [0.93773743, 0.1805304 , 0.20340427, 0.09459392, 0.01531   ,\n",
       "        0.19365326],\n",
       "       [0.67229603, 0.40960124, 0.60547651, 0.01567967, 0.11506466,\n",
       "        0.01254374]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.preprocessing import Normalizer \n",
    "# 取到数据 Fresh 到最后\n",
    "normalizer=Normalizer().fit(data.iloc[:,2:])\n",
    "data_=normalizer.transform(data.iloc[:,2:])\n",
    "data_\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 轮廓系数找到最优K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAjFElEQVR4nO3deXiV9Zn/8fd9ThKWsJOEYFiCgCCgIITFZRzcCtW2aIstoChuDGO12s411Wln+pu205na1pYuLgOIe6X8cKk/S8Ha2lanwxIUi2GRCFTCvu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       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.cluster import KMeans \n",
    "from sklearn.metrics import silhouette_score #轮廓系数\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "cluster = KMeans(n_clusters=3, random_state=0).fit(data_)\n",
    "silhouette_score(data_,cluster.labels_)\n",
    "\n",
    "score=[]\n",
    "for i in range(2,7):\n",
    "    cluster=KMeans(n_clusters=i,random_state=0).fit(data_)\n",
    "    score.append(silhouette_score(data_,cluster.labels_))\n",
    "\n",
    "\n",
    "plt.plot(range(2,7),score)\n",
    "#plt.axvline(pd.DataFrame(score).idxmin()[0]+2,ls=':')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 建模及可视化分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Fresh</th>\n",
       "      <th>Milk</th>\n",
       "      <th>Grocery</th>\n",
       "      <th>Frozen</th>\n",
       "      <th>Detergents_Paper</th>\n",
       "      <th>Delicassen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.575088</td>\n",
       "      <td>0.233245</td>\n",
       "      <td>0.279252</td>\n",
       "      <td>0.625425</td>\n",
       "      <td>0.053748</td>\n",
       "      <td>0.109052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.902462</td>\n",
       "      <td>0.179160</td>\n",
       "      <td>0.229113</td>\n",
       "      <td>0.149695</td>\n",
       "      <td>0.049047</td>\n",
       "      <td>0.074455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.254118</td>\n",
       "      <td>0.486061</td>\n",
       "      <td>0.684665</td>\n",
       "      <td>0.095721</td>\n",
       "      <td>0.271384</td>\n",
       "      <td>0.097196</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Fresh      Milk   Grocery    Frozen  Detergents_Paper  Delicassen\n",
       "0  0.575088  0.233245  0.279252  0.625425          0.053748    0.109052\n",
       "1  0.902462  0.179160  0.229113  0.149695          0.049047    0.074455\n",
       "2  0.254118  0.486061  0.684665  0.095721          0.271384    0.097196"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "cluster = KMeans(n_clusters=3,random_state=0).fit(data_)\n",
    "\n",
    "data1=pd.DataFrame(cluster.cluster_centers_,columns=[\"Fresh\",\"Milk\",\"Grocery\",\"Frozen\",\"Detergents_Paper\",\"Delicassen\"])\n",
    "data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x193e0195550>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAgA0lEQVR4nO3deXxU1f3/8de9M5OVMFkIawiDYRPlCwqubC4/RY1axYfigk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ckmRRMpySZFEynJJkUTKckmRRMpySZFEynJJkUf8f5iX1Q4ZAl1wAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_=plt.pie(data1.iloc[:,0],autopct='%0.2f%%')\n",
    "plt.legend(\"012\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x193e04afd00>"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD1CAYAAABA+A6aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAdA0lEQVR4nO3deXRUZbrv8e9DAIOIaWVwIC3BvjJnIAkhiI0MDQGMICgq0AzaNqCC05UFLGlE8Fyx1bb7Ci3iEZFrizmNDXKVViZBwQGChkAYBDyxSeNlEnMIQ0PIe/9IqBPKJFXBSirZ/D5ruVb23m/teqpKfnnz1q6nzDmHiIjUfnXCXYCIiISGAl1ExCMU6CIiHqFAFxHxCAW6iIhHKNBFRDyibrjuuEmTJi4mJiZcdy8iUitt3rz5sHOuaVnHwhboMTExZGZmhuvuRURqJTP7trxjWnIREfEIBbqIiEco0EVEPCJsa+hlOXPmDHl5eZw6dSrcpUg1iIyMJDo6mnr16oW7FBFPqFGBnpeXR6NGjYiJicHMwl2OVCHnHEeOHCEvL4+WLVuGuxwRT6hRSy6nTp2icePGCvOLgJnRuHFj/TUmEkI1KtABhflFRK+1SGjVuEAPt4iICBISEnz/5ebm/qTzxcTEcPjw4dAUJyJSgRq1hu4vZvL7IT1f7qxbAo5p0KABWVlZZR5zzuGco04d/R6sbsH8vxDM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kQoEXHJxzhWa2XjgQyACmO+cyzGzcSXH5wLLgf7AHuAEcE/VlVxrXBRLSx6m16/2umhfu4BvioqISO2gT4qKiHiEAl1ExCMU6CIiHqHvFA0RM2tD8Sdmm1N8Df5+YJlzbkdYCxPxuJJ/e82BL5xzBaX293XOfRC+yqqfZughYGaTKG6JYMBGii/1NGBRWc3MpPYwM12xVYOZ2UPAu8AEYJuZlW5L8r/CU1X46CqXEDCzr4H2zrkzfvvrAznOuRvCU5n8VGb2D+fcdeGuQ8pmZluBLs65AjOLARYD/8c59ycz+8o51zG8FVYvLbmERhFwLfCt3/5rSo5JDWZm2eUdAq6qzlqk0iLOLbM453LNrDuw2MxaUHZLEk9ToIfGI8BqM9sN7CvZdx3wP4Dx5d1IaoyrgDTgqN9+Az6t/nKkEv6fmSU457IASmbq6cB8IDaslYWBAj0EnHMfmFkrilsNN6c4CPKATc65s2EtToLxHnDZuVAozczWVns1UhkjgcLSO5xzhRS3InklPCWFj9bQRUQ8Qle5iIh4hAJdRMQjFOgiIh6hQBcR8QgFuoiIR/x/D7LtTp0m24QAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data1.plot.bar()\n",
    "plt.legend(loc=\"upper left\")\n",
    "\n",
    "#_=plt.bar(data1.index,data1.value_counts,color = 'orange',width = 0.5,yerr = 4,ecolor = 'red',capsize = 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.57508847, 0.23324504, 0.27925177, 0.6254248 , 0.05374771,\n",
       "        0.10905186],\n",
       "       [0.9024623 , 0.17915962, 0.22911268, 0.14969506, 0.04904731,\n",
       "        0.07445492],\n",
       "       [0.25411803, 0.48606066, 0.68466474, 0.09572091, 0.27138443,\n",
       "        0.09719618]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# def randCent(dataSet, k):\n",
    "#     n = dataSet.shape[1] # n为列数，iris    一共5列\n",
    "#     data_min = dataSet.iloc[:, :n-1].min() # 前4列，每一列最    小值\n",
    "#     data_max = dataSet.iloc[:, :n-1].max() # 前4列，每一列最    大值\n",
    "#     data_cent = np.random.uniform(data_min,data_max,(k, n-1)) # 均匀分布中抽样，    形状为(k, n-1)\n",
    "#     return data_cent\n",
    "\n",
    "# def distEclud(arrA, arrB):\n",
    "#     d = arrA - arrB\n",
    "#     dist = np.sum(np.power(d, 2), axis=1)\n",
    "#     return dist\n",
    "\n",
    "# def kMeans(dataSet, k, distMeas=distEclud, createCent=randCent): # iris为150*5\n",
    "#     m,n = dataSet.shape # m是行数（数据    量），n是列数iris为150*5\n",
    "#     # 下面生成的centroids，即第一个容器，后面用来存储最新更新的质心\n",
    "#     centroids = createCent(dataSet, k) # centroids为    3*4，用三个长度为4的一维数组记载3个质心\n",
    "#     # 第一次    centroids是随机生成的\n",
    "#     # 这段生成的result_set，即第二个容器\n",
    "#     # result_set结构： [数据集, 该行到最近质心的距离， 本次迭代中最近质心编号，上次迭代中最    近质心编号]\n",
    "#     clusterAssment = np.zeros((m,3)) # clusterAssment为150*3的数组\n",
    "#     clusterAssment[:, 0] = np.inf # np.inf为无穷大\n",
    "#     clusterAssment[:, 1: 3] = -1 # 此时clusterAssment为150*3\n",
    "#     result_set = pd.concat([dataSet, pd.DataFrame(clusterAssment)],axis=1,ignore_index = True) # result_set为150*8\n",
    "#     clusterChanged = True\n",
    "#     while clusterChanged:\n",
    "#         clusterChanged = False\n",
    "#         for i in range(m): # 遍历result_set中每一行，一共m行\n",
    "#             # 小心，下面的n为5，而resulit_set的列数已经变成8\n",
    "#             dist = distMeas(dataSet.iloc[i, :n-1].values, centroids) # 第i 行与三个质心的距离,dist为3*1\n",
    "#             result_set.iloc[i, n] = dist.min() # result_set[i,n] 记录该行与3个质心的最小距离\n",
    "#             result_set.iloc[i, n+1] = np.where(dist == dist.min())[0] # result_set[i,n] 记录最近质心的索引\n",
    "#             clusterChanged = not (result_set.iloc[:, -1] == result_set.iloc[:,-2]).all()\n",
    "#                         # 只要result_set最后两列不完全相等，意味着本次for循环结束时，m行所有的新质心与上次while循环留下的不完全一样\n",
    "#                         # 后果：clusterChanged为True，while继续循环\n",
    "#                         # clusterChanged为True，则需要运行下面的if语句代码块，重置第一个容器centroids和第二个容器result_set\n",
    "#         if clusterChanged:\n",
    "#             cent_df = result_set.groupby(n+1).mean() # 按照列索引为 n+1 （质心索引）(第6列)进行分组求均值\n",
    "#                                                     # 即：按照最新的    簇分类，计算最新3个质心的位置\n",
    "#             centroids = cent_df.iloc[:,:n-1].values # 重置centroids，用最新质心位置，替换上次的。3*4\n",
    "#             result_set.iloc[:, -1] = result_set.iloc[:, -2] # result_set最\n",
    "\n",
    "#     return centroids, result_set\n",
    "\n",
    "\n",
    "# cent,result=kMeans(data1,3)    \n",
    "# cent,result"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "7ef57b1a12f99e7c74e468f4512270929d1986b547266cbc198c69385640fc98"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 64-bit ('base': conda)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
